﻿Imports CapaLogica
Imports CapaLogica.CL.Carrera
Imports CapaLogica.CL.UtilidadesGenerales
Imports CapaLogica.CL.Grupo
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections

Public Class frmRegistrarCurso

    Private Sub FrmRegistrarCurso_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cargarCarreras()
    End Sub

    Public Sub cargarCarreras()

        Dim list As New List(Of Informacion)

        list = GestorCarrera.listarTodasLasCarreras()

        For Each carrera As EsCarrera In list
            ltBoxCarrerasSinAsociar.Items.Add(carrera)
        Next

        ltBoxCarrerasSinAsociar.DisplayMember = "nombre"
        ltBoxCarrerasAsociadas.DisplayMember = "nombre"

    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        Try

            If txtCodigoCurso.Text = Nothing Or txtNombreCurso.Text = Nothing Or txtDescripcion.Text = Nothing Then
                MsgBox("Los campos 'Codigo Curso', 'Nombre', 'Descripcion' son requeridos", MsgBoxStyle.Exclamation, "Error")
            Else
                If ltBoxCarrerasAsociadas.Items.Count = 0 Then
                    MsgBox("Debe seleccionar la(as) carrera(as) asociada al curso a registrar", MsgBoxStyle.Exclamation, "Error")
                Else
                    Dim Pregunta As Integer
                    Pregunta = MsgBox("¿Desea registrar el curso al Sistema?.", vbYesNo + vbExclamation + vbDefaultButton2, "Eliminar Curso.")
                    If Pregunta = vbYes Then
                        Dim listaC As New List(Of Int32)
                        listaC = obtenerIdsDeListBox(ltBoxCarrerasAsociadas)
                        GestorCurso.registrarCurso(txtCodigoCurso.Text, txtNombreCurso.Text, txtDescripcion.Text, listaC)
                        MsgBox("El curso ha sido registrado.")
                        limpiarCampos()

                    Else
                        MsgBox("Curso no Registrado!")
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
        End Try

    End Sub

    Private Sub btnAsociarCarreraCurso_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAsociarCarreraCurso.Click
        cambiarElementosDeListas(ltBoxCarrerasAsociadas, ltBoxCarrerasSinAsociar)
    End Sub

    Private Sub btnDesasociarCarreraCurso_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDesasociarCarreraCurso.Click
        cambiarElementosDeListas(ltBoxCarrerasSinAsociar, ltBoxCarrerasAsociadas)
    End Sub

    Private Sub limpiarCampos()
        txtCodigoCurso.Text = Nothing
        txtNombreCurso.Text = Nothing
        txtDescripcion.Text = Nothing
        limpiarListBox(ltBoxCarrerasSinAsociar)
        limpiarListBox(ltBoxCarrerasAsociadas)
        cargarCarreras()
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        limpiarCampos()
    End Sub

    Private Sub ToolStripButton3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        Me.Dispose()
    End Sub
End Class

